home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / MATH / CURVE11.ZIP / CURVE.DOC next >
Text File  |  1993-09-07  |  10KB  |  285 lines

  1.  
  2.                               CURVE FITTER
  3.  
  4.                                version 1.1
  5.  
  6.  
  7.  
  8.                                    by
  9.  
  10.                               David C. Young
  11.  
  12.  
  13. For use with MSDOS computers.
  14.  
  15. Copyright 1991 David C. Young
  16.  
  17.  
  18.  
  19.  
  20. PROGRAM FUNCTION:
  21.  
  22.     This program finds both coefficients and exponents for a curve of best 
  23. fit by the least squares definition of best fit.
  24.  
  25.     The program contains functions for creating and revising it's data 
  26. input files.  There is also a function titled "Display any ASCII file", which 
  27. can be used to display the output files.
  28.  
  29.     Each data field is read from a data file.  Each data point in the file 
  30. is accompanied by a key piece of information, which uniquely identifies that 
  31. data point.
  32.  
  33.     The program will read in any number of data files and only use those 
  34. data points containing information for every field.
  35.  
  36.  
  37. STARTING THE PROGRAM:
  38.  
  39.     Start the program by changing to the directory or drive containing the 
  40. program and typing CURVE.
  41.  
  42.     The program can be installed on a hard drive by using the DOS copy 
  43. command to copy all of the files to the desired location on the hard drive.
  44.  
  45.  
  46. USING THE PROGRAM:
  47.  
  48.     The basic process of using this program is:
  49.  
  50.         1.  Create data files.  The data in the data files is keyed.
  51. An example of using keys would be if you wanted to find an equation to
  52. predict the price of your favorite stock, you might want to enter various
  53. items that could be used to predict, such as Gross National Product, or
  54. the price of tea in China.  The price of your stock would also be in a file
  55. keyed by month.  You would key these values by the date that they are for.  
  56. Thus you would have a file with the price of tea in China during various 
  57. months.  The month would be the key value.  Once you had several files, all 
  58. keyed by month, you might guess that the price of your stock varies in the
  59. same way as the GNP times the price of tea in China.  
  60.         If you don't have all of the necessary data (due to irregular 
  61. delivery of the Bejing Times), the program will still work.  It will just
  62. only take into account those months, for which you have a complete set of
  63. data, without bothering you with the details.
  64.  
  65.         2.  Type in an equation.  For the example above, the equation
  66. might be S=A*G*T+B or S=A*S^C+B*T^D+E where S is the stock price, G is
  67. the GNP, T is the price of tea in China and A through E are numbers that
  68. you want the computer to calculate.
  69.  
  70.         3.  Specify which letters represent known data points to be 
  71. read from data files.  S, G & T in our example are read from files.  
  72. C & D are computed exponents.  A, B & E are computed coeficients.
  73.  
  74.         4.  Input file names for summary and analysis files.  
  75. A summary file contains the stuff put on screen at the end of the calculation,
  76. the values for computed numbers and the average & maximum deviations (measures
  77. of how well the equation fits the data).  An analysis file contains the 
  78. key values, actual values (for your stock) and computed values.  Analysis
  79. files can be read into many popular spread sheets and graphing programs,
  80. so that you can graph the data to better see how well the calculation 
  81. works.
  82.  
  83.         5.  For computed exponents, input starting values and the 
  84. number of decimal places to calculate.
  85.  
  86.     The equation to be input consists of single upper or lower case 
  87. letters to represent both known pieces of data and numbers to be calculated, 
  88. along with an equals sign "=" and four mathematical operators:
  89.  
  90.         "+" - addition
  91.  
  92.         "*" - multiplication
  93.  
  94.         "/" - division
  95.  
  96.         "^" - exponentiation
  97.  
  98.     Some examples of valid equations are:
  99.  
  100.         a = b * c + d
  101.  
  102.         a * b^c + d = e
  103.  
  104.         a = b * C^d * E^e + f * g^h + i
  105.  
  106.         A=B*C^D+E*F^G+H*I^J+K*L^M+N
  107.  
  108.  
  109. DATA FILE FORMAT:
  110.  
  111.     The data file is an ASCII file consisting of a header and up to 65000 
  112. key and data values.
  113.  
  114.     The numbers identifying what type of key and data values are present 
  115. are as follows:
  116.  
  117.         1 - string
  118.         2 - real
  119.         3 - character
  120.         4 - integer
  121.  
  122.     The key field can be of any of these types.  The data field can be 
  123. used for curve fitting only if it is of type real or integer.  Integer data 
  124. fields are treated by curve fitter as real values.
  125.  
  126.     The data file format is:
  127.  
  128. <number of data points (integer)>
  129. <file description (string)>
  130. <type of key field (string)>
  131. <type of key field (integer)>
  132. <type of data field (string)>
  133. <type of data field (integer)>
  134. <key value (first)> <data value (first)>
  135. <key value (second)> <data value (second)>
  136.     .
  137.     .
  138.     .
  139. <key value (last)> <data value (last)>
  140. <end of file>
  141.  
  142.  
  143. SUMMARY FILE FORMAT:
  144.  
  145.     The summary file is an ASCII file, which contains exactly the same 
  146. information, which is displayed on the screen at the end of a calculation.
  147.  
  148.     The summary file format is:
  149.  
  150.     <equation (string)>
  151.  
  152. Average Deviation = <average deviation (real)>
  153. Maximum Deviation = <maximum deviation (real)>
  154.  
  155.     Known data points
  156. Known <letter in equation> taken from <file name>
  157. (same as line above for each data file used)
  158.  
  159.     Computed Exponents (if any)
  160. Exponent <letter in equation> = <value (real)>
  161. (same as line above for each exponent computed)
  162.  
  163.     Computed Coefficients
  164. Coefficients <letter in equation> = <value (real)>
  165. (same as line above for each coefficient computed)
  166. <end of file>
  167.  
  168.  
  169. ANALYSIS FILE FORMAT:
  170.  
  171.     The analysis file is an ASCII file containing information for 
  172. comparing the known values to the calculated values for the property being 
  173. modeled.
  174.  
  175.     The analysis file format is:
  176.  
  177. <number of data points (integer).
  178. <equation (string)>
  179. <type of key field (string)>
  180. <type of key field (integer - same as data file)>
  181. <type of data field (string)>
  182. <type of data field (integer - same as data file)>
  183. <key value (first)> <known data value> <calculated data value>
  184. <key value (second)> <known data value> <calculated data value>
  185.     .
  186.     .
  187.     .
  188. <key value (last)> <known data value> <calculated data value>
  189. <end of file>
  190.  
  191.  
  192. LIMITATIONS OF THE PROGRAM:
  193.  
  194.     Some known deficiencies with the program that I hope to get around to 
  195. fixing in the future are.
  196.  
  197.         1.  Parenthesis are not allowed in the equations.
  198.  
  199.         2.  Constants are not allowed, although you can create a data 
  200. file with the same number for every data point if necessary.
  201.  
  202.         3.  The list of functions which are not supported is massive.  
  203. It starts with the trigonometric functions.
  204.  
  205.         4.  The exponents that are found represent local minimums
  206. only, so pick your initial values wisely, or try a few that you think might
  207. be in the right range.
  208.  
  209.     However, to the best of my knowledge, for what this program does do, 
  210. it does it correctly.
  211.  
  212.  
  213. ABOUT CURVE FITTING:
  214.  
  215.     The program generally finds the coefficients of best fit for each term 
  216. in an equation and finds the exponent of best fit for any variable desired.  
  217. The exponents are gotten through a multivarible simplex minimization routine.  
  218. The coefficients are gotten at every step of the way through the matrix 
  219. algebra least squares method (mathematically equivalent to linear regression).
  220.  
  221.     If your theory shows that an equation should have a particular form, 
  222. it is best to work with that form.  However, if you don't know what form to 
  223. use and want to fit your data by a brute force method, here are some 
  224. suggestions:
  225.  
  226.         1.  Have the program find a coefficient for every term in the 
  227. equation.
  228.  
  229.         2.  Have the program find the constant term.
  230.  
  231.         3.  The generic most powerful fitting is one in which every 
  232. term consists of a fitted coefficient and a single variable with a fitted 
  233. exponent .. and then the constant term is added on.  This is often the best 
  234. fit because the most parameters are being fitted.
  235.  
  236.         4.  Remember that you can fit anything if you are fitting more 
  237. parameters than there are items in your data set, however this fit may be 
  238. useless when applied to new data points falling between or past the original 
  239. data points.  For best results always make sure that you have considerably 
  240. more data points than the number of parameters that are being fitted, 
  241. otherwise you may be fooling yourself.
  242.  
  243.  
  244. LEGAL STUFF:
  245.  
  246.     Version 1.1 of this program is being offered FREE to the world with no 
  247. guarantees expressed or implied ... etc, etc, etc.  Version 1.1 may be freely
  248. distributed to anyone and everyone, as long as these instructions are
  249. kept with it.
  250.  
  251.  
  252. SALES PITCH:
  253.  
  254.     I have completed version 2.1 of this program.  The new features
  255. present in version 2.1 are:
  256.  
  257.         1.  It allows multiple character identifiers.
  258.  
  259.         2.  It allows user inserted parenthesis.
  260.  
  261.         3.  It allows the use of numerical constants.
  262.  
  263.         4.  It has twenty new functions covering trigonometry,
  264. logarithms and a few others items.
  265.  
  266.     If you would like to buy version 2.1, send $15.00 to:
  267.  
  268.         David Young
  269.         4485 Fairlane
  270.         Okemos, MI  48864
  271.  
  272. Please, specify what size and density of disk for me to send.  I will send
  273. you one disk containing version 2.1 (or whatever the most recent version is)
  274. containing the program and documentation files.  This price does not include
  275. any updates past the version that I send you, but I will try to keep you
  276. informed of future versions.  Please, send cash, check or money orders.  I 
  277. cannot accept credit card orders.  Version 2.1 is sold as is with no 
  278. guarantees expressed or implied.
  279.  
  280.     If you have any questions, you can also reach me by e-mail at:
  281.  
  282.         internet:  young@slater.cem.msu.edu
  283.         bitnet:    YOUNGDC@MSUCEM
  284.  
  285.